import * as http from 'http';
import querystring from "querystring";
import mgrRecord from './mgrRecord';
import { OnRecieve } from './NetGame';
// import EventDispatcher from './extensions/EventDispatcher';
// import { MSG } from './common/Const';

let DEBUG = false;

let server = http.createServer(function (req, rsp: http.ServerResponse) {
    DEBUG && console.log(`url:${req.url}, method:${req.method}`);
    if (req.url == "/ck/onefigure" && req.method == "POST") {
        let data = "";
        req.on("data", function (chunck) {
            data += chunck;
        })

        req.on("end", function () {
            data = querystring.parse(data);

            DEBUG && console.log("recieve:", data);

            try {
                OnRecieve(data, rsp);
                rsp.end();
            } catch (error) {
                console.log("rsp err:", error);
                rsp.end();
            }
        })
    }
})
server.listen(50001);

// init
mgrRecord.onload();

console.log("---> start server..");
